package GUI;


/**
 *
 * @author dirk
 */
import java.util.*;

public class GameWorld
{
	// List of Location objects
	private Vector locations;

	// List of Exit objects
	private Vector exits;

	// The current location of the player
	private Location currentLocation;

	// Character width for descriptions
	private int charWidth;

	// GameWorld constructor
	public GameWorld()
	{
		// Instantiate vector lists for location/exits
		locations = new Vector();
		exits = new Vector();

		// The default location of a player isn't known
		currentLocation = null;

	}

	// GameWorld constructor
	public GameWorld(int characterWidth )
	{
		// Call default constructor
		this();

		charWidth = characterWidth;
	}

	/** Returns the current location of the player */
	public Location getCurrentLocation()
	{
		return currentLocation;
	}

	/** Assigns a new location to the current location of the player */
	public void setCurrentLocation(Location newLocation)
	{
		currentLocation = newLocation;
	}

	/** Adds a new exit to the gaming system */
	public void addExit( Exit exit )
	{
		// Check if exit vector already contains exit
		if (! exits.contains ( exit ) )
			// Exit doesn't exist, and must be added
			exits.addElement ( exit);
	}

	/** Adds a new location to the gaming system */
	public void addLocation( Location location )
	{
		// Check if location vector already contains location
		if (! locations.contains ( location ) )
			// Location doesn't exist, and must be added
			locations.addElement ( location );
	}


        public String getExitsString()
        {
            String returnString = "";

             for (Enumeration e = currentLocation.getExits().elements(); e.hasMoreElements();)
            {
                    // Get next exit
                    Exit an_exit = (Exit) e.nextElement();
                    // Print exit to our output stream
                    returnString = returnString + " " +(an_exit.getShortDirectionName());
            }
            return returnString;

        }


        //** Shows the current game location -> text */
        public String getLocationString()
        {
            String returnString = ( currentLocation.getTitle() ) +
                                  "\n" + ( currentLocation.getDescription() ) + "\n" +
                                  "\n" +( "Available exits :" ) + getExitsString();

            return returnString;

        }
	/** Shows the current game location */
	public void showLocation()
	{                      
		// Show title
		System.out.println ( currentLocation.getTitle() );

		// Show description
		System.out.println ( currentLocation.getDescription() );
                
		System.out.println();

		// Show available exits
		System.out.println ( "Available exits :" );

		// Traverse elements of vector
		for (Enumeration e = currentLocation.getExits().elements(); e.hasMoreElements();)
		{
			// Get next exit
			Exit an_exit = (Exit) e.nextElement();

			// Print exit to our output stream
			System.out.println (an_exit.toString());
		}
	}

        public String getBlockageString()
        {
              return currentLocation.getBlockDescription() +"\n"
                      +"...press any button to go back";
        }
        public void showBlockage()
        {
            System.out.println(currentLocation.getBlockDescription());
            System.out.println("You need the following item to pass: "+currentLocation.getNeedItem());
            System.out.println();
		// Show available exits
		System.out.println ( "Available exits :\nBACK" );
        }

}


